package indi.zhifa.study2024.class002.busy.generalTest.controller.nbr;


import indi.zhifa.study2024.class002.busy.generalTest.business.curd.bill.consign.entity.po.ConsignHeadEntity;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.bill.consign.entity.request.ConsignBillCreateRequest;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.bill.consign.entity.request.ConsignBillModifyRequest;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.bill.consign.entity.response.ConsignVo;
import indi.zhifa.study2024.class002.busy.generalTest.business.curd.bill.consign.service.IConsignService;
import indi.zhifa.study2024.class002.busy.generalTest.enums.bill.EBillStatus;
import indi.zhifa.study2024.core.common.web.entity.ann.ZhiFaRestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping(value = "/class002/nbr/curd/consign")
@ZhiFaRestController
@Tag(name = "销售单增删改查")
public class ConsignBillController {

    final IConsignService mConsignService;

    @Operation(summary = "创建销售单")
    @PostMapping
    public ConsignVo create(@RequestBody ConsignBillCreateRequest pConsignBillRequest){
        return mConsignService.create(pConsignBillRequest);
    }

    @Operation(summary = "创建销售单")
    @GetMapping("/{id}")
    public ConsignVo info(@PathVariable(name = "id") Long pId){
        return mConsignService.info(pId);
    }

    @Operation(summary = "创建销售单")
    @PostMapping("/{id}")
    public ConsignHeadEntity changeStatus(@PathVariable(name = "id") Long pId,
                                   @RequestParam(name = "billStatus") EBillStatus pEBillStatus){
        return mConsignService.changeStatus(pId, pEBillStatus);
    }

    @Operation(summary = "修改销售单")
    @PutMapping("/{id}")
    public ConsignVo edit(@PathVariable(name = "id") Long pId,
                   @RequestBody ConsignBillModifyRequest pConsignBillModifyRequest){
        return mConsignService.edit(pId, pConsignBillModifyRequest);
    }

    @Operation(summary = "删除销售单")
    @DeleteMapping("/{id}")
    public ConsignVo delete(@PathVariable(name = "id") Long pId){
        return mConsignService.delete(pId);
    }
}
